#!/usr/bin/env python3

import argparse
import os
import sys

try:
    from rosidl_generator_c import generate_c
except ImportError:
    # modifying sys.path and importing the Python package with the same
    # name as this script does not work on Windows
    rosidl_generator_c_root = os.path.dirname(os.path.dirname(__file__))
    rosidl_generator_c_module = os.path.join(
        rosidl_generator_c_root, 'rosidl_generator_c', '__init__.py')
    if not os.path.exists(rosidl_generator_c_module):
        raise
    from importlib.machinery import SourceFileLoader

    loader = SourceFileLoader('rosidl_generator_c', rosidl_generator_c_module)
    rosidl_generator_c = loader.load_module()
    generate_c = rosidl_generator_c.generate_c


def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        description='Generate the C ROS interfaces.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        '--generator-arguments-file',
        required=True,
        help='The location of the file containing the generator arguments')
    parser.add_argument(
        '--disable-description-codegen', action='store_true',
        help='If set, disable the generation of static type description '
             'code to reduce binary size.')
    args = parser.parse_args(argv)

    generate_c(args.generator_arguments_file, args.disable_description_codegen)


if __name__ == '__main__':
    sys.exit(main())
